// 权限管理相关API
import request from '../utils/request'

// 获取权限列表
export const getPermissionList = (params) => {
  return request({
    url: '/api/permissions',
    method: 'get',
    params
  })
}

// 获取权限详情
export const getPermissionDetail = (id) => {
  return request({
    url: `/api/permissions/${id}`,
    method: 'get'
  })
}

// 创建权限
export const createPermission = (data) => {
  return request({
    url: '/api/permissions',
    method: 'post',
    data
  })
}

// 更新权限
export const updatePermission = (id, data) => {
  return request({
    url: `/api/permissions/${id}`,
    method: 'put',
    data
  })
}

// 删除权限
export const deletePermission = (id) => {
  return request({
    url: `/api/permissions/${id}`,
    method: 'delete'
  })
}

// 更新权限状态
export const updatePermissionStatus = (id, status) => {
  return request({
    url: `/api/permissions/${id}/status`,
    method: 'put',
    data: { status }
  })
}

// 获取角色权限列表
export const getRolePermissions = (roleId) => {
  return request({
    url: `/api/roles/${roleId}/permissions`,
    method: 'get'
  })
}

// 更新角色权限
export const updateRolePermissions = (roleId, permissionIds) => {
  return request({
    url: `/api/roles/${roleId}/permissions`,
    method: 'put',
    data: { permissionIds }
  })
}